// 语言资源
const languageResources = {
  en: {
    versionTitle: "Official Version",
    testPackageTitle: "Test Package",
    scanQRCode: "Scan QR Code to Download",
    updatedOn: "Updated on:",
    openInBrowser: "Open the page in the browser to download",
    clickMenu: "Click the menu in the top-right corner",
    downloadInstall: "Download and Install",
    downloadTitle: "Download on the",
    // 应用商城
    appStore: "App Store",
    googlePlay: "Google Play",
  },
  zh: {
    versionTitle: "正式版",
    testPackageTitle: "测试包",
    scanQRCode: "扫描二维码下载",
    updatedOn: "更新于：",
    openInBrowser: "在浏览器中打开页面下载",
    clickMenu: "点击右上角菜单",
    downloadInstall: "浏览器下载",
    downloadTitle: "应用商城",
    appStore: "App Store",
    googlePlay: "Google Play",
  },
};

// 获取系统语言
const userLang = navigator.language || navigator.userLanguage;
const lang = userLang.includes("zh") ? "zh" : "en"; // 中文和英文

// 设置页面内容
document.getElementById("test-package-title").textContent = languageResources[lang].testPackageTitle;
document.getElementById("scan-qr-code").textContent = languageResources[lang].scanQRCode;
document.getElementById("updated-on").textContent = languageResources[lang].updatedOn;
document.getElementById("open-in-browser").textContent = languageResources[lang].openInBrowser;
document.getElementById("click-menu").textContent = languageResources[lang].clickMenu;

const deviceOS = getDeviceOS();
// 获取按钮元素
const button = document.getElementById("download-install");
button.querySelector("img").src = deviceOS === "iOS" ? "./static/Apple.png" : "./static/Playstore.png";
button.querySelector("span:first-child").textContent =languageResources[lang].downloadTitle ;
button.querySelector("span:last-child").textContent = deviceOS === "iOS" ? languageResources[lang].appStore : languageResources[lang].googlePlay;


const button2 = document.getElementById("download-install-now");
button2.querySelector("img").src = "./static/download.png";
button2.querySelector("span").textContent = languageResources[lang].downloadInstall;
if (deviceOS === "iOS") { 
  button2.remove();
}
// 如果文案需要多个则设置页面内容
const elements = document.querySelectorAll(".version-title");
elements.forEach((element) => {
  if (element.classList.contains("version-title")) {
    element.textContent = languageResources[lang].versionTitle;
  }
});


function getDeviceOS() {
  const userAgent = navigator.userAgent || navigator.vendor || window.opera;

  // 判断 iOS
  if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
    return "iOS";
  }

  // 判断 Android
  if (/android/i.test(userAgent)) {
    return "Android";
  }

  return "Unknown";
}
